package com.sie.project.controller;

import com.google.gson.Gson;
import com.sie.project.entity.*;
import com.sie.project.service.ProjectService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author linjinde
 */
@CrossOrigin
@RestController("/project")
public class ProjectController {

    @Resource
    ProjectService projectService;
    /**
     *  获取项目选择下拉
     * @return 所有项目
     */
    @GetMapping("/getProjectSelector")
    public String getProjectSelector() {
        List<ProjectSelectVo> projectSelects = projectService.getProjectSelect();
        Gson gson = new Gson();
        return  gson.toJson(projectSelects);
    }
    /**
     *  获取当年每个月得统计情况
     * @return int[]
     */
    @GetMapping("/getMonthStatistics")
    public String getProjectClassByYear(@RequestParam("className") String className, @RequestParam("type") String type) {
        int[] projectClassByYear = projectService.getProjectClassByYear(type, className);
        Gson gson = new Gson();
        return gson.toJson(projectClassByYear);
    }

    /**
     * 获取项目清单
     */
    @GetMapping("/getProjectList")
    public String getProjectListByType(@RequestParam("type") String type){
        List<Project> projectsByTye = projectService.getProjectsByType(type);
        Gson gson = new Gson();
        return gson.toJson(projectsByTye);
    }
    @GetMapping("/getProjectLateList")
    public String getProjectListLateByType(@RequestParam("type") String type){
        List<Project> projectsByTye = projectService.getProjectLateByType(type);
        Gson gson = new Gson();
        return gson.toJson(projectsByTye);
    }

    /**
     * 项目统计四个圆圈
     * @param type 开发项目OR销售项目
     * @return 项目情况
     */
    @GetMapping("/getProjectStatistics")
    public String getProjectStatistics(@RequestParam("type") String type){
        List<ProjectTaskDTO> projectStatistics = projectService.getProjectStatistics(type);
        Gson gson = new Gson();
        return gson.toJson(projectStatistics);
    }

    /**
     * 项目详情
     * @param projectId 项目id
     * @return 项目信息
     */
    @GetMapping("/getProjectDetail")
    public String getProjectDetail(@RequestParam("projectId")String projectId){
        Project projectDetail = projectService.getProjectDetail(projectId);
        Gson gson = new Gson();
        return gson.toJson(projectDetail);
    }

    /**
     *  获取项目目标列表
     * @param projectId 项目id
     * @return 目标列表
     */
    @GetMapping("/getProjectTargetList")
    public String getProjectTargetList(@RequestParam("projectId")String projectId){
        List<ProjectTarget> projectTargetList = projectService.getProjectTargetList(projectId);
        Gson gson = new Gson();
        return gson.toJson(projectTargetList);
    }

    /**
     *  项目里程碑列表
     * @param projectId 项目ID
     * @return 里程碑列表
     */
    @GetMapping("/getProjectMilestoneList")
    public String getProjectMilestoneList(@RequestParam("projectId")String projectId){
        List<ProjectMilestone> projectMilestoneList = projectService.getProjectMilestoneList(projectId);
        Gson gson = new Gson();
        return  gson.toJson(projectMilestoneList);
    }

    /**
     * 统计任务情况
     * @param projectId 项目id
     * @return 统计任务情况
     */
    @GetMapping("/getTaskStatistic")
    public String getTaskStatistic(@RequestParam("projectId")String projectId){
        ProjectTaskStatistic taskStatistic = projectService.getTaskStatistic(projectId);
        Gson gson = new Gson();
        return gson.toJson(taskStatistic);
    }

    /**
     *  获取项目延期任务清单
     * @param projectId 项目id
     * @return 项目延期任务清单
     */
    @GetMapping("/getDelayTasks")
    public String getDelayTasks(@RequestParam("projectId")String projectId){
        List<ProjectTaskDTO> tasksByExtension = projectService.getTasksByExtension(projectId);
        Gson gson = new Gson();
        return gson.toJson(tasksByExtension);
    }

    /**
     *  获取项目问题清单
     * @param projectId 项目id
     * @return 项目问题清单
     */
    @GetMapping("/getIssuesList")
    public String getIssuesList(@RequestParam("projectId")String projectId) {
        List<ProjectIssues> issuesList = projectService.getIssuesList(projectId);
        Gson gson = new Gson();
        return  gson.toJson(issuesList);
    }

    /**
     *  统计项目问题优先级
     * @param projectId 项目id
     * @return 统计项目问题优先级
     */
    @GetMapping("/getIssuesStatistic")
    public String getIssuesStatistic(@RequestParam("projectId")String projectId){
        List<IssuesStatistic> issuesStatistics = projectService.getIssuesStatistics(projectId);
        Gson gson = new Gson();
        return  gson.toJson(issuesStatistics);
    }

    /**
     *  获取风险列表
     * @param projectId 项目id
     * @return 风险列表
     */
    @GetMapping("/getRiskList")
    public String getRiskList(@RequestParam("projectId")String projectId){
        List<ProjectRisk> riskList = projectService.getRiskList(projectId);
        Gson gson = new Gson();
        return  gson.toJson(riskList);
    }

    /**
     *  风险统计
     * @param projectId 项目id
     * @return f
     */
    @GetMapping("/getRiskStatistic")
    public String getRiskStatistic(@RequestParam("projectId")String projectId){
        List<RiskStatistic> riskStatistic = projectService.getRiskStatistic(projectId);
        Gson gson = new Gson();
        return  gson.toJson(riskStatistic);
    }

    /**
     *  项目资源列表
     * @param projectId
     * @return
     */
    @GetMapping("/getMembers")
    public String getMembers(@RequestParam("projectId")String projectId){
        List<ProjectMemberRes> projectMemberRes = projectService.getProjectMemberRes(projectId);
        System.out.println(projectMemberRes);
        Gson gson = new Gson();
        return gson.toJson(projectMemberRes);
    }




}

